<?php
/*
AceGame. Web browser MMORPG.
Copyright(C) 2012 Aceapps Aplicaciones. 
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses
*/

	// Session Start

	session_start();

	// Load files

	require_once '../include/functions.php';

	// Login Validation

	if (!session_validate()) {
		header('Location: ../');
		exit;
	}

	// Get session variables

	$userid = $_SESSION['id'];
	$accesslevel = $_SESSION['accesslevel'];

	// Character amount verification info
		
	$query = "SELECT c.id,c.name,r.name,m.name FROM characters AS c,races AS r,maps AS m
			WHERE c.user = '$userid' AND c.race = r.id AND c.map = m.id";
	$result = mysql_query($query) or die(mysql_error());
	$numrows = mysql_num_rows($result);

	// Profile

	$tabs = '<li id="tabHeader_1">Profile</li>';
	$content = '<div class="tabpage" id="tabpage_1">';

	if ($accesslevel >= 100) {
		$content .= '<p><input type="submit" value="admin panel" class="submit"
			onClick="location.href=\'../admin/index.php\'" /></p>';
	}

	$content .= '<p>Coming soon...</p></div>';

	// Char Selection

	$i = 2;
	while ($row = mysql_fetch_array($result)) {
		$tabs .= '<li id="tabHeader_'.$i.'">'.$row[1].'</li>';

		$content .= '<div class="tabpage" id="tabpage_'.$i.'">
				<table><tr>
					<td><img name="pic" src="images/Neutral '.$row[2].'.png" border="0"></td>
					<td>@ '.$row[3].'</td>
					<td><input type="submit" value="play!" name="play" class="submit"
						onClick="location.href=\'sc.php?id='.$row[0].'\'" /></td>
				</tr></table>
			</div>';
		$i++;
	}

	// Create Character

	if ($numrows < $maxchars) {
		// Get races list

		$query = "SELECT name,playable,accesslevel,id FROM races";
		$result = mysql_query($query) or die(mysql_error());

		$tabs .= '<li id="tabHeader_'.$i.'">Create Character</li>';
			
		$content .= '<div class="tabpage" id="tabpage_'.$i.'">';

		// Characer Creation Form

		$content .= '<form id="cc" name="cc" action="cc.php" method="post" accept-charset="UTF-8">
				<legend>Select a Race</legend>';

		// Fill selection with races

		while ($row = mysql_fetch_array($result)) {
			if (($accesslevel >= $row[2]) & ($row[1]))
				$content .= '<p>
				<input type="submit" value="'.$row[0].'" name="'.$row[3].'" class="submit" />
				<img src="images/Good '.$row[0].'" width="64" height="64">
				<img src="images/Neutral '.$row[0].'" width="64" height="64">
				<img src="images/Evil '.$row[0].'" width="64" height="64"></p>';
		}

		// End Form

		$content .= '</form></div>';

		$i++;
	}

	// Load HTML5 Template

	include_once '../template/header.php';

	// Print

	echo '<div class="tabs">
			<ul>
			'.$tabs.'
			</ul>
		</div>

		<div class="tabscontent">
			'.$content.'
		</div>';

	// Load HTML5 Template

	include_once '../template/footer.php';
?>
